//
//  DMAttentionCell.m
//  CQKuaiYi
//
//  Created by 何典钊 on 2017/1/9.
//  Copyright © 2017年 Mr.Cannon. All rights reserved.
//

#import "DMAttentionCell.h"
#import "UIImageView+WebCache.h"
@implementation DMAttentionCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}

- (void)setModel:(DMDoctorModel *)model {
    _model = model;
    
    _dmCollection.text = model.banner;
    _dmFlowers.text = model.flower;
    _dmCount.text = model.operation_count;
    _dmName.text = model.doctor_name;
    _dmProfessional.text = model.doctor_title_name;
    //    _dmHospital.text = model.doctor_hospital_name;
    
    self.dmHospital.text = model.hospital_name;
    
    NSURL *url = [NSURL URLWithString:model.doctor_portrait];
    [self.dmIcon sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"doctor_defaultphoto_male"]];
}


- (void)setupUI {
    
    //声明
    _dmIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"doctor_defaultphoto_male"]];
    
    _dmName = [UILabel cz_labelWithText:@"何典钊" fontSize:14 color:[UIColor blackColor]];
    
    _dmProfessional = [UILabel cz_labelWithText:@"心理医生" fontSize:14 color:[UIColor blackColor]];
    
    _dmHospital = [UILabel cz_labelWithText:@"北京协和医院" fontSize:14 color:[UIColor blackColor]];
    _dmCount = [UILabel cz_labelWithText:@"1" fontSize:14 color:[UIColor blackColor]];
    
    UIImageView *flowers = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"flower"]];
    _dmFlowers = [UILabel cz_labelWithText:@"2" fontSize:14 color:[UIColor blackColor]];
    
    UIImageView *jinqi = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"star"]];
    _dmCollection = [UILabel cz_labelWithText:@"3" fontSize:14 color:[UIColor blackColor]];
    
    
    //添加
    [self.contentView addSubview:_dmIcon];
    [self.contentView addSubview:_dmName];
    [self.contentView addSubview:_dmProfessional];
    [self.contentView addSubview:_dmHospital];
    [self.contentView addSubview:_dmCount];
    [self.contentView addSubview:flowers];
    [self.contentView addSubview:_dmFlowers];
    [self.contentView addSubview:jinqi];
    [self.contentView addSubview:_dmCollection];
    
    //添加约束
    [_dmIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(45, 45));
        make.top.left.equalTo(self.contentView).offset(8);
    }];
    
    [_dmName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_dmIcon.mas_right).offset(16);
        make.top.equalTo(_dmIcon);
    }];
    
    [_dmProfessional mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.centerY.equalTo(_dmName);
        make.left.equalTo(_dmName.mas_right).offset(15);
    }];
    
    [_dmHospital mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_dmName);
        make.top.equalTo(_dmName.mas_bottom).offset(10);
    }];
    
    [_dmCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_dmIcon).offset(90);
        make.top.equalTo(_dmHospital.mas_bottom).offset(10);
        make.bottom.equalTo(self.contentView).offset(-3);
    }];
    
    [flowers mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_dmIcon.mas_bottom);
        make.left.equalTo(_dmCount.mas_right).offset(48);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
    
    [_dmFlowers mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_dmCount);
        make.left.equalTo(flowers.mas_right).offset(5);
    }];
    
    [jinqi mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(flowers);
        make.left.equalTo(flowers.mas_right).offset(63);
        make.top.equalTo(flowers);
    }];
    
    [_dmCollection mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(jinqi.mas_right).offset(5);
        make.centerY.equalTo(_dmCount);
    }];
}

@end
